using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using PS.WebParts.Rollup;

namespace PS.WebParts
{
    [PersistChildren(false), ParseChildren(true), SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class AggregateDataSource : ATabularDataSource
    {
        protected override ATabularDataSourceView CreateViewInstance()
        {
            return new AggregateDataView(base.Context, this);
        }
        
        private AggregateDataView GetAggregateView()
        {
            return (AggregateDataView)base.GetView();
        }

        [Browsable(true), PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string Aggregate
        {
            get
            {
                return this.GetAggregateView().Aggregate;
            }
            set
            {
                this.GetAggregateView().Aggregate = value;
            }
        }

        [Browsable(false), Personalizable(PersonalizationScope.Shared, true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string DataSourcesString
        {
            get
            {
                return this.GetAggregateView().DataSourcesString;
            }
            set
            {
                this.GetAggregateView().DataSourcesString = value;
            }
        }

        [Browsable(true), Personalizable(PersonalizationScope.Shared, true)]
        public string LanguageVersion
        {
            get
            {
                return this.GetAggregateView().LanguageVersion;
            }
            set
            {
                this.GetAggregateView().LanguageVersion = value;
            }
        }
        
        //public bool HasSeparateRoot { get; }

        [WebPartStorage(Storage.None), PersistenceMode(PersistenceMode.InnerProperty), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public DataSourceCollection Sources
        {
            get
            {
                return this.GetAggregateView().GetDataSources();
            }
        }

        ///<summary>
        ///Gets the named data source view associated with the data source control.
        ///</summary>
        ///
        ///<returns>
        ///Returns the named <see cref="T:System.Web.UI.DataSourceView"></see> associated with the <see cref="T:System.Web.UI.DataSourceControl"></see>.
        ///</returns>
        ///
        ///<param name="viewName">The name of the <see cref="T:System.Web.UI.DataSourceView"></see> to retrieve. In data source controls that support only one view, such as <see cref="T:System.Web.UI.WebControls.SqlDataSource"></see>, this parameter is ignored. </param>
        protected override DataSourceView GetView(string viewName)
        {
            return this.GetAggregateView();
        }
    }
}
